package com.alit.face.koala.service.system;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alit.face.koala.app.data.AppResponse;
import com.alit.face.koala.app.data.BoxData;
import com.alit.face.koala.app.data.Page;
import com.litong.utils.projectvariable.PVU;

@Service
public class ScreenService {

  private List<BoxData> boxDataList = null;

  public AppResponse screen(Integer size) {
    AppResponse appResponse = new AppResponse();
    Page page = new Page();
    page.setCount(10);
    page.setSize(10);
    page.setCurrent(1);
    page.setTotal(1);
    appResponse.setCode(0);
    appResponse.setPage(page);
    appResponse.setData(getListBoxData());
    return appResponse;
  }

  private List<BoxData> getListBoxData() {
    // 测试数据,不要每次读盘,每次转
    if (boxDataList == null) {  
      File file = new File(PVU.getJsonFilePath("BoxData.json"));
      String string = null;
      try {
        string = FileUtils.readFileToString(file, "UTF-8");
      } catch (IOException e) {
        e.printStackTrace();
      }
      boxDataList = JSON.parseArray(string, BoxData.class);
    }
    return boxDataList;
  }
}
